package com.zte.stats.control;

import com.zte.stats.model.*;
import com.zte.stats.service.IStatsSalesService;
import com.zte.util.PageModel;
import com.zte.util.ResultMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/sales")
public class StatsSalesAction {

    @Autowired
    private IStatsSalesService iStatsService;

    @RequestMapping("/custom")
    @ResponseBody
    public ResultMessage queryCustomOrdersByCondition(PageModel<StatsCustom> pageModel, StatsCustomCondition scc) {
        PageModel<StatsCustom> customPageModel = iStatsService.queryCustomOrdersByCondition(pageModel, scc);
        ResultMessage msg = new ResultMessage();
        msg.setStatus(200);
        msg.setFlag(true);
        msg.setMsg("查询客户成功！");
        msg.setData(customPageModel);
        return msg;
    }

    @RequestMapping("/orders")
    @ResponseBody
    public ResultMessage queryOrdersByCondition(PageModel<StatsOrders> pageModel, StatsCustomCondition scc) {
        PageModel<StatsOrders> statsOrders = iStatsService.queryOrdersByCondition(pageModel, scc);
        ResultMessage msg = new ResultMessage();
        msg.setStatus(200);
        msg.setFlag(true);
        msg.setMsg("查询订单成功！");
        msg.setData(statsOrders);
        return msg;
    }

    @RequestMapping("/city")
    @ResponseBody
//    @Cacheable(cacheNames = {"city"})
    public ResultMessage queryCityList(StatsCustomCondition scc) {
        List<StatsCity> statsCities = iStatsService.queryCityList(scc);
        ResultMessage msg = new ResultMessage();
        msg.setStatus(200);
        msg.setFlag(true);
        msg.setMsg("查询城市成功！");
        msg.setData(statsCities);
        return msg;
    }

    @RequestMapping("/province")
    @ResponseBody
    public ResultMessage queryProvince() {
        List<StatsProvince> statsProvinces = iStatsService.queryProvince();
        ResultMessage msg = new ResultMessage();
        msg.setStatus(200);
        msg.setFlag(true);
        msg.setMsg("查询省份成功！");
        msg.setData(statsProvinces);
        return msg;
    }
}
